/**
 * @fileOverview Main module
 */

/**
 * @namespace Main namespace
 * @description Main namespace that will contain all other classes and namespaces
 */
var app = {};

$(function() {
	app.debug(app, app.player);

	$('#test').click(function() {
		var timer = new app.Timer({
			handler : function() {
				console.log(this.iterations);
			},
			duration : 5,
			interval : 1/3
		});
		
		timer.start();
	
		return false;
	});
	
	$('#fight-start').click(function() {
		var fight = new app.Fight({
			attacker : app.playerGroup,
			target : new app.UnitGroup([app.UnitMgr.create('rat')])
		});
		var fightLog = function(msg) {
			$('<li>').html(app.Util.format.apply(this, Array.prototype.slice.call(arguments))).appendTo('#fight-log ul');
		}
		
		$('#fight-log ul').empty();
		
		fight.bind({
			'start' : function(groups) {
				fightLog('Fight between <b>%s</b> and <b>%s</b>', groups[0].getName(), groups[1].getName());
			},
			'complete' : function() {
				fightLog('Fight completed');
			},
			'hit' : function(unit, target, amount, attribute) {
				fightLog('<b>%s</b> hit <b>%s</b> for <b>%i %s</b> damage', unit, target, amount, attribute);
			},
			'skillused' : function(unit, target, skill) {
				fightLog('<b>%s</b> used <b>%s</b> on <b>%s</b>', unit, skill, target);
			},
			'restoreused' : function(unit, target, amount, attribute) {
				fightLog('<b>%s</b> restored <b>%i %s</b> to <b>%s</b>', unit, amount, attribute, target);
			}
		}).start();
		
		return false;
	});
});